void itoa(int value, char *str, int radix)
{
    assert(str != NULL);

    if (value < 0) { //如果是负数,则str[0]='-',并把value取反(变成正整数)
        str[0] = '-';
        value = 0 - value;
    }

    const char asc[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int i, j;

    for(i = 1; value > 0; i++, value /= radix) { //从value[1]开始存放value的数字字符，不过是逆序，等下再反序过来
        str[i] = asc[value % radix]; //将获得该数字的ASCII值
    }

    str[i] = '\0';

    for(j = i - 1, i = 1; j - i >= 1; j--, i++) { //将数字字符反序存放
        str[i] = str[i] ^ str[j];
        str[j] = str[i] ^ str[j];
        str[i] = str[i] ^ str[j];
    }

    if('-' != str[0]) { //如果不是负数，则需要把数字字符下标左移一位，即减1
        for(i = 0; str[i + 1] != '\0'; i++) {
            str[i] = str[i + 1];
        }

        str[i] = '\0';
    }
}

